package com.example.kafka.kerberos.mock;

import com.example.kafka.kerberos.common.CommonResult;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author stone
 * @version $1.0
 * @date 2020/9/17 16:20:18
 */
@RestController
public class KafkaCenterController {

    @GetMapping("/cluster")
    @ResponseBody
    public CommonResult cluster() throws Exception {
        CommonResult result = new CommonResult();
        result.setCode("200");

        HashMap<String, String> map = new HashMap<>();

        String path = "/home/stone/gitee/kafka-kerberos/src/main/resources/static/cluster.json";
        BufferedReader reader = new BufferedReader(new FileReader(path));
        StringBuilder builder = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            builder.append(line);
        }
        String jsonStr = builder.toString();
        ObjectMapper mapper = new ObjectMapper();
        Map<String, String> value = mapper.readValue(jsonStr, Map.class);
        ArrayList<Map<String,String>> arrayList = new ArrayList<>();
        arrayList.add(value);
        result.setData(arrayList);
        return result;
    }

}
